﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nancy;
using PlatWL.Data;
using PlatWL.Models;
using Nancy.ModelBinding;
using PlatWL.Services.Services;
using Nancy.Security;


namespace PlatWL.Modules.Admin
{
    public class BaseModule : AdminModule
    {
        public BaseModule(BaseManage service) : base("base")
        {
            this.RequiresAuthentication();

            #region 分类管理
            //查询分类
            Get["/cate/list/{infotype}/{topid?0}"] = p =>
            {
                service.Cate_List(ref msg, Client, page, p.infotype, p.topid);
                return this.Response.AsJson(msg);
            };
            //添加分类
            Post["/cate/add"] = p =>
            {
                var ad = this.Bind<pt_base_category>();
                service.Cate_Add(ref msg, Client, ad);
                return this.Response.AsJson(msg);
            };

            //分类model
            Get["/cate/model/{id:int}"] = p =>
            {
                service.Cate_Model(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };
            
            //删除分类
            Get["/cate/del/{id:int}"] = p =>
            {
                service.Cate_Del(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };

            //设置显示或隐藏
            Get["/cate/hide/{id:int}"] = p =>
            {
                service.Cate_Hide(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };

            #endregion

            # region 获取档案信息
                
                Get["/sender/list"] = p =>
                {
                    string searchinfo =Context.Request.Query["searchkey"];
                    string type = Context.Request.Query["Type"];
                    service.Sender_List(ref msg, Client, page, searchinfo, type);
                    return this.Response.AsJson(msg);
                };

            Get["/logistic/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
                string type = Context.Request.Query["Type"];
                service.Logistic_List(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            Get["/car/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
               // string type = Context.Request.Query["Type"];
                service.car_List(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            Get["/driver/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
                // string type = Context.Request.Query["Type"];
                service.driver_List(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            Get["/receiver/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
                // string type = Context.Request.Query["Type"];
                service.receiver_List(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            Get["/order/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
                // string type = Context.Request.Query["Type"];
                service.order_List(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            //Get["/ordercar/list"] = p =>
            //{
            //    string searchinfo = Context.Request.Query["searchkey"];
            //    // string type = Context.Request.Query["Type"];
            //    service.order_List(ref msg, Client, page, searchinfo);
            //    return this.Response.AsJson(msg);
            //};

            Get["/distince/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
                // string type = Context.Request.Query["Type"];
                service.distince_List(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            Get["/transfer/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
                // string type = Context.Request.Query["Type"];
                service.Transfer_List(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            Get["/transfer1/list"] = p =>
            {
                string searchinfo = Context.Request.Query["searchkey"];
                // string type = Context.Request.Query["Type"];
                service.Transfer_List1(ref msg, Client, page, searchinfo);
                return this.Response.AsJson(msg);
            };

            Post["/updatecar"] = p =>
            {

                string orderid =Context.Request.Form["orderid"];
                var car = Context.Request.Form["carid"];

                // string type = Context.Request.Query["Type"];
                service.Update_car(ref msg, Client, page, car, orderid);
                return this.Response.AsJson(msg);
            };
            #endregion


        }

    }
}